#ifndef _MAINWINDOW_H_
#define _MAINWINDOW_H_

#include <Windows.h>
#include "GL/gl.h"
#include "GL/glu.h"

#include "game_engine.hpp"

#define SCALE (50)
#define HEIGHT (20)
#define WIDTH (10)

// The main window class. It wraps the HANDLE of the window and initializes the 
// openGL rendering context. It is also in charge of processing the different
// event messages.
class CMainWindow
{
public:
	CMainWindow(int iWidth, int iHeight, bool bFullScreen);
	~CMainWindow();

	// Called by the application class to update the game logic
	void Update(DWORD dwCurrentTime);
  void drawWorm(Point3D pos, Point3D base, Point3D MG_pos, double temp_t, game_engine *eng, int index);
	// Called by the application class when the window need to be redrawn.
	void Draw();

  int completed_rows;
  void tick();

private:
	// Register the window class with the correct window procedure (OnEvent)
	void RegisterWindowClass();
	// Create the rendering context used by OpenGL
	void CreateContext();
	// Initialize openGL
	void InitGL();

	// Called when a WM_SIZE message is received
	void OnSize(GLsizei width, GLsizei height);

	// Static function which will be the window procedure callback
    static LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam);
	// Processes the messages that were received in OnEvent.
	void ProcessEvent(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam);

	// The window handle
	HWND	m_hWindow;
	// The window device context
    HDC     m_hDeviceContext;
	// The openGL context.
    HGLRC   m_hGLContext;    

	// Specifies if the window is fullscreen.
	bool m_bFullScreen;

  void drawBorder();
  void drawCube(double,double,double);
  void drawMG(int s_sten);
  bool draw_it();

  int mouse_x, mouse_y, x_rot_angle, y_rot_angle, z_rot_angle;
  unsigned int last_motion_time;
  int last_motion_diff, last_motion_button[3];
  int shift, scale;
  
  double g_x, g_y;

  int rot_tick_conn_valid;
  int multi;
  
  double multi_colours[6][3];
  game_engine eng;
  
  int sten;

};

#endif  // _MAINWINDOW_H_